'use strict';

angular.module('snPaas_om')
	.controller('MysqlListCtrl',['$scope','baseUrl','ngDialog','mysqlClusterStore','SpSlider',function($scope,baseUrl,ngDialog,mysqlClusterStore,SpSlider){

		
		$scope.baseUrl = baseUrl.static;
		$scope.newSolution = function(){
			var d = ngDialog.open({
				template: baseUrl.static+'template/views/newMysql.html',
				controller: 'NewMysqlCtrl',
				width:830
			});
			d.closePromise.then(function(){
				loadingList();
			});
		};
		var loadingList = function(){
			mysqlClusterStore.query().then(function(data){
				$scope.clusterList = data;
			});	
		};
		loadingList();

		$scope.removeCluster = function(item){
			var d = ngDialog.open({
				template: baseUrl.static+'template/views/confirm.html',
				controller: 'ConfirmCtrl',
				width:430,
				data:{
					text:'确定要删除集群'+item.mysqlClusterName+'吗？'
				},
				closeByEscape:false,
				closeByDocument:false,
				showClose:false
			});
			d.closePromise.then(function(res){
				if(res.value =='yes'){
					mysqlClusterStore.remove(item.deployId).then(function(){
						loadingList();
						SpSlider.slideIn({
							title:'操作成功',
							content:'集群'+item.mysqlClusterName+'已删除',
							type:'noti'
						});
					});	
				}
			});
			
		};
	
	}]);